package org.nicocube.airain.app.client.table;

import java.util.LinkedList;
import java.util.List;

import com.google.gwt.user.client.ui.HTMLTable;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class Item {
	private static final String DaGridIdent = "daGridIdent";
	private static final String DaGridValue = "daGridValue";

	private String identClassName;
	private String ident;

	private String valueClassName;
	private List<Widget> widgets;
	private int rank;

	public Item() {
		this(DaGridIdent,DaGridValue);
	}

	public Item(String identClassName,String valueClassName) {
		this.identClassName = identClassName;
		this.valueClassName = valueClassName;
		this.widgets = new LinkedList<Widget>();
	}

	public Item setIdent(String ident) {
		this.ident = ident;
		return this;
	}

	public Item addValue(String value) {
		Label lValue = new Label(value);
		lValue.setStylePrimaryName(valueClassName);
		widgets.add(lValue);
		return this;
	}

	public Item addWidget(Widget w) {
		widgets.add(w);
		return this;
	}

	public void render(int row, HTMLTable g) {
		Label lIdent = new Label(ident);
		lIdent.setStylePrimaryName(identClassName);
		g.setWidget(row, 0, lIdent);

		int i=1;		
		for (Widget value : widgets) {
			g.setWidget(row, i, value);
			i++;
		}
	}

	public int getRank() {
		return rank;
	}

	public void setRank(int rank) {
		this.rank = rank;
	}

}